home *** CD-ROM | disk | FTP | other *** search
/ APC & TCP 4 / APC & TCP 4.iso / games / publicdomain / a / asteroids2 / rotx / fire.c < prev    next >
C/C++ Source or Header  |  1995-07-20  |  8KB  |  330 lines

  1.  #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <graphics/gfxmacros.h>
  4. #include <stdio.h>
  5. #include <h/rot.h>
  6. #include <h/extern.h>
  7.  
  8. /*
  9. #define MWDEBUG 1
  10. #include "sc:extras/memlib/memwatch.h"
  11. */
  12.  
  13. InitFire(n)
  14. LONG n;
  15. {
  16. LONG x,num;
  17.  
  18. num = -1;
  19. for(x=0;x<ship[n].fnum;x++)
  20.     if (ship[n].shotI[x].flight == FALSE)
  21.         {
  22.         num = x;
  23.         break;
  24.         }
  25.  
  26. if (num != -1)
  27.     {
  28.     ship[n].shotI[x].range = 24;
  29.     if (n < control.playernum) makesound(0,0);
  30.     else                      makesound(5,0);
  31.     ship[n].shotI[x].xp = ship[n].x+id[ship[n].image+ship[n].pos].wi/2+ship[n].vx/100;
  32.     ship[n].shotI[x].yp = ship[n].y+id[ship[n].image+ship[n].pos].he/2+ship[n].vy/100;
  33.     ship[n].shotI[x].vx = ship[n].fvmax*VxINC[ship[n].pos];
  34.     ship[n].shotI[x].vy = ship[n].fvmax*VyINC[ship[n].pos];
  35.     ship[n].shotI[x].len = ship[n].flen;
  36.     ship[n].shotI[x].pos = ship[n].pos;
  37.     ship[n].shotI[x].dx = (ship[n].shotI[x].len * VxINC[ship[n].shotI[x].pos]) /100;
  38.     ship[n].shotI[x].dy = (ship[n].shotI[x].len * VyINC[ship[n].shotI[x].pos]) /100;
  39.     ship[n].shotI[x].flight = TRUE;
  40.     }
  41. }
  42.  
  43.  
  44. Init360Fire(n,pos)
  45. LONG n;
  46. {
  47. LONG x,num;
  48.  
  49. num = -1;
  50. for(x=0;x<ship[n].fnum;x++)
  51.     if (ship[n].shotI[x].flight == FALSE)
  52.         {
  53.         num = x;
  54.         break;
  55.         }
  56.  
  57. if (num != -1)
  58.     {
  59.     ship[n].shotI[x].range = 24;
  60.     ship[n].shotI[x].xp = ship[n].x+id[ship[n].image+ship[n].pos].wi/2;
  61.     ship[n].shotI[x].yp = ship[n].y+id[ship[n].image+ship[n].pos].he/2;
  62.     ship[n].shotI[x].vx = ship[n].fvmax*VxINC[pos];
  63.     ship[n].shotI[x].vy = ship[n].fvmax*VyINC[pos];
  64.     ship[n].shotI[x].len = ship[n].flen;
  65.     ship[n].shotI[x].pos = pos;
  66.     ship[n].shotI[x].dx = (ship[n].shotI[x].len * VxINC[ship[n].shotI[x].pos]) /100;
  67.     ship[n].shotI[x].dy = (ship[n].shotI[x].len * VyINC[ship[n].shotI[x].pos]) /100;
  68.     ship[n].shotI[x].flight = TRUE;
  69.     }
  70. }
  71.  
  72.  
  73. DrawFire(n)
  74. LONG n;
  75. {
  76. LONG x;
  77. LONG xx,yy;
  78. LONG dx,dy;
  79.  
  80. for(x=0;x<ship[n].fnum;x++)
  81.     if (ship[n].shotI[x].flight == TRUE)
  82.         {
  83.         ship[n].shotI[x].oxp = ship[n].shotI[x].xp;
  84.         ship[n].shotI[x].oyp = ship[n].shotI[x].yp;
  85.         ship[n].shotI[x].opos = ship[n].shotI[x].pos;
  86.  
  87.         xx = ship[n].shotI[x].xp += ship[n].shotI[x].vx/100;
  88.         yy = ship[n].shotI[x].yp += ship[n].shotI[x].vy/100;
  89.  
  90.         dx = ship[n].shotI[x].dx;
  91.         dy = ship[n].shotI[x].dy;
  92.  
  93.         CollisionFireSaucer(n,x,xx+dx,yy+dy);
  94.         CollisionFireAsteroids(n,x,xx+dx,yy+dy);
  95.         CollisionFireShips(n,x,xx+dx,yy+dy);
  96.         CollisionFireFighters(n,x,xx+dx,yy+dy);
  97.  
  98.         if (control.firewrap == FALSE)
  99.             {
  100.             if ( (xx > gi.x2+10) || (xx < gi.x1-10) ||
  101.                 (yy > gi.y2+10) || (yy < gi.y1-10))
  102.                     ship[n].shotI[x].flight = LAST;
  103.             }
  104.         else
  105.             {
  106.             if (--ship[n].shotI[x].range == 0)    ship[n].shotI[x].flight = LAST;
  107.             if (xx > gi.x2) ship[n].shotI[x].xp = gi.x1;
  108.             if (xx < gi.x1) ship[n].shotI[x].xp = gi.x2;
  109.             if (yy > gi.y2) ship[n].shotI[x].yp = gi.y1;
  110.             if (yy < gi.y1) ship[n].shotI[x].yp = gi.y2;
  111.             }
  112.  
  113.  
  114.         if (ship[n].shotI[x].flight == TRUE)
  115.             {
  116.             SetAPen(rp1[bit],1);
  117.             SetWrMsk(rp1[bit],0xfd);
  118.             Move(rp1[bit],ship[n].shotI[x].xp,ship[n].shotI[x].yp);
  119.             Draw(rp1[bit],ship[n].shotI[x].xp+dx,ship[n].shotI[x].yp+dy);
  120.             }
  121.         }
  122. }
  123.  
  124.  
  125.  
  126. EraseFire(n)
  127. LONG n;
  128. {
  129. LONG x,xx,yy;
  130. LONG dx,dy;
  131.  
  132. for(x=0;x<ship[n].fnum;x++)
  133. {
  134. if (ship[n].shotI[x].flight != FALSE)
  135.     {
  136.     xx = ship[n].shotI[x].oxp;
  137.     yy = ship[n].shotI[x].oyp;
  138.  
  139.     dx = (ship[n].shotI[x].len * VxINC[ship[n].shotI[x].opos])/100;
  140.     dy = (ship[n].shotI[x].len * VyINC[ship[n].shotI[x].opos])/100;
  141.  
  142.     SetWrMsk(rp1[1-bit],0xfd);
  143.     Move(rp1[1-bit],xx,yy);
  144.     Draw(rp1[1-bit],xx+dx,yy+dy);
  145.  
  146.     if (ship[n].shotI[x].flight == LAST) ship[n].shotI[x].flight = FALSE;
  147.     }
  148. }    
  149. }
  150.  
  151.  
  152. InitPlasmaBall(n)
  153. {
  154. LONG x,num;
  155.  
  156. num = -1;
  157. for(x=0;x<ship[n].pnum;x++)
  158.     if (ship[n].photI[x].flight == FALSE)
  159.         if (ship[n].photI[x].delay == 0)
  160.             {
  161.             num = x;
  162.             break;
  163.             }
  164.  
  165. if (num != -1)
  166.     {
  167.     ship[n].photI[x].xp = ship[n].x+id[ship[n].image].wi/2;
  168.     ship[n].photI[x].yp = ship[n].y+id[ship[n].image].he/2;
  169.     ship[n].photI[x].vx = ship[n].pvmax;
  170.     ship[n].photI[x].vy = ship[n].pvmax;
  171.     ship[n].photI[x].pos = ship[n].pos;
  172.     ship[n].photI[x].turn = 0;
  173.     ship[n].photI[x].range = ship[n].prange;
  174.     ship[n].photI[x].flight = TRUE;
  175.     ship[n].photI[x].delay = ship[n].pdelay;
  176.     ship[n].photI[x].type = SEEKING;
  177.     ship[n].photI[x].wrap = TRUE;
  178.     ship[n].photI[x].image = ship[n].pimage;
  179.     }
  180. }
  181.  
  182.  
  183. InitSidePlasmaBall(n)
  184. {
  185. LONG x,num,y;
  186. LONG wi,he;
  187.  
  188. num = -1;
  189. for(x=0;x<ship[n].pnum;x++)
  190.     if (ship[n].photI[x].flight == FALSE)
  191.         if (ship[n].photI[x].delay == 0)
  192.             {
  193.             num = x;
  194.             break;
  195.             }
  196.  
  197. if ((num != -1) && (ship[ship[n].aim].pilot != DESTROYED))
  198.     {
  199.     wi = id[ship[n].image+ship[n].pos].wi;
  200.     he = id[ship[n].image+ship[n].pos].he;
  201.  
  202.     if (Random(100.0) < 50) y = wi/4;
  203.     else                    y =-wi/4;
  204.  
  205.     ship[n].photI[x].xp = ship[n].x+wi/2+(y*VyINC[ship[n].pos])/100;
  206.     ship[n].photI[x].yp = ship[n].y+he/2-(y*VxINC[ship[n].pos])/100;
  207.     ship[n].photI[x].vx = ship[n].pvmax;
  208.     ship[n].photI[x].vy = ship[n].pvmax;
  209.     ship[n].photI[x].pos = ship[n].pos;
  210.     ship[n].photI[x].turn = 0;
  211.     ship[n].photI[x].range = ship[n].prange;
  212.     ship[n].photI[x].flight = TRUE;
  213.     ship[n].photI[x].delay = ship[n].pdelay;
  214.     ship[n].photI[x].wrap = TRUE;
  215.     ship[n].photI[x].type = SEEKING;
  216.     ship[n].photI[x].image = ship[n].pimage;
  217.     }
  218. }
  219.  
  220.  
  221.  
  222. DrawPhoton(n)
  223. LONG n;
  224. {
  225. LONG x;
  226.  
  227. for(x=0;x<ship[n].pnum;x++)
  228.     {
  229.     if (--ship[n].photI[x].delay < 0) ship[n].photI[x].delay=0;
  230.  
  231.     if (ship[n].photI[x].flight != FALSE)
  232.         {
  233.         ship[n].photI[x].oxp = ship[n].photI[x].xp;
  234.         ship[n].photI[x].oyp = ship[n].photI[x].yp;
  235.  
  236.         CollisionPhotonShips(n,x);
  237.         if (n < control.playernum)
  238.             {
  239.             CollisionPhotonFighters(n,x);
  240.             CollisionPhotonAsteroids(n,x);
  241.             CollisionPhotonSaucer(n,x);
  242.             CollisionPhotonBattleship(n,x);
  243.             }
  244.  
  245.         if (ship[n].photI[x].type == SEEKING) HandleSeeking(n,x);
  246.         if (ship[n].photI[x].wrap == TRUE)
  247.             CheckPhotonWrap(n,x);
  248.         else    CheckPhotonEnd(n,x);
  249.         
  250.         CheckRange(n,x);
  251.  
  252.         if (ship[n].photI[x].flight == TRUE)
  253.             {
  254.             SetAPen(rp1[bit],1);
  255.             SetWrMsk(rp1[bit],0xfd);
  256.             ship[n].photI[x].xp += ship[n].photI[x].vx*VxINC[ship[n].photI[x].pos]/100;
  257.             ship[n].photI[x].yp += ship[n].photI[x].vy*VyINC[ship[n].photI[x].pos]/100;
  258.             if (n < control.playernum)
  259.                 BltTemplate(id[il.photon].data,0,2,rp1[bit],ship[n].photI[x].xp,ship[n].photI[x].yp,id[il.photon].wi,id[il.photon].he);
  260.             else
  261.                 BltTemplate(id[il.photon+1].data,0,2,rp1[bit],ship[n].photI[x].xp,ship[n].photI[x].yp,id[il.photon+1].wi,id[il.photon+1].he);
  262.             }
  263.          }
  264.     }
  265. }
  266.  
  267.  
  268. CheckPhotonWrap(n,x)
  269. LONG n,x;
  270. {
  271. if (ship[n].photI[x].xp > gi.x2+10) ship[n].photI[x].xp = gi.x1-10;
  272. else
  273. if (ship[n].photI[x].xp < gi.x1-10) ship[n].photI[x].xp = gi.x2+10;
  274. if (ship[n].photI[x].yp > gi.y2+10) ship[n].photI[x].yp = gi.y1-10;
  275. else
  276. if (ship[n].photI[x].yp < gi.y1-10) ship[n].photI[x].yp = gi.y2+10;
  277. }
  278.  
  279. CheckRange(n,x)
  280. LONG n,x;
  281. {
  282. if (--ship[n].photI[x].range == 0)    ship[n].photI[x].flight = LAST;
  283. }
  284.  
  285.  
  286. CheckPhotonEnd(n,x)
  287. LONG n,x;
  288. {
  289. if ((ship[n].photI[x].xp > gi.x2+10) ||
  290.     (ship[n].photI[x].xp < gi.x1-10) ||
  291.     (ship[n].photI[x].yp > gi.y2+10) ||
  292.     (ship[n].photI[x].yp < gi.y1-10))
  293.         ship[n].photI[x].flight = LAST;
  294. }
  295.  
  296. ErasePhoton(n)
  297. LONG n;
  298. {
  299. LONG x;
  300.  
  301. SetWrMsk(rp1[1-bit],0xfd);
  302. for(x=0;x<ship[n].pnum;x++)
  303. {
  304. if (ship[n].photI[x].flight != FALSE)
  305.     {
  306.     RectFill(rp1[1-bit],ship[n].photI[x].oxp,ship[n].photI[x].oyp,
  307.              ship[n].photI[x].oxp+id[ship[n].photI[x].image].wi,ship[n].photI[x].oyp+id[ship[n].photI[x].image].he);
  308.  
  309.     if (ship[n].photI[x].flight == LAST) ship[n].photI[x].flight = FALSE;
  310.     }
  311. }    
  312. }
  313.  
  314.  
  315. HandleSeeking(n,x)
  316. LONG n,x;
  317. {
  318. LONG direction;
  319.  
  320. if (++ship[n].photI[x].turn >= ship[n].pman)
  321.     {
  322.     ship[n].photI[x].turn = 0;
  323.     direction = detcomplexheading(n,ship[ship[n].aim].x,ship[ship[n].aim].y,ship[n].photI[x].xp,ship[n].photI[x].yp,ship[n].photI[x].pos);
  324.     if (direction != 0) ship[n].photI[x].pos+=sign(direction);
  325.  
  326.     if (ship[n].photI[x].pos > 31)  ship[n].photI[x].pos= 0;
  327.     if (ship[n].photI[x].pos <  0)  ship[n].photI[x].pos=31;
  328.     }
  329. }
  330.